﻿@model object
@{
    Layout = ViewBag.Layout ?? "_TR.cshtml";
    ViewData.TemplateInfo.HtmlFieldPrefix = ViewData.TemplateInfo.HtmlFieldPrefix.Replace(ViewData.ModelMetadata.PropertyName, "").Trim('.');
    var propertyName = ViewData["name"] == null ? ViewData.ModelMetadata.PropertyName : ViewData["name"].ToString();

    var editorHtmlAttributes = Html.GetUnobtrusiveValidationAttributes(propertyName, ViewData.ModelMetadata).Merge(ViewData.ModelMetadata.AdditionalValues, true);
    var htmlAttributes = ViewBag.HtmlAttributes;
    if (htmlAttributes != null)
    {
        if (htmlAttributes is IDictionary<string, object>)
        {
            editorHtmlAttributes.Merge((IDictionary<string, object>)htmlAttributes);
        }
        else
        {
            editorHtmlAttributes.Merge(new RouteValueDictionary(htmlAttributes));
        }
    }
}
@Html.TextBox(propertyName, Model, editorHtmlAttributes)
@Html.ValidationMessage(ViewData.ModelMetadata, new { name = ViewData["name"] })

<em class="tip">@Html.Raw((ViewData.ModelMetadata.Description ?? "").Localize())</em>

<em id="sampleRule">
    @("Example:".Localize())
    <a data-regex="(/Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/)">@("Mobiles".Localize())</a>
    <a data-regex="(android)">@("Android".Localize())</a>
    <a data-regex="(iPhone)">@("iPhone".Localize())</a>
    <a data-regex="(ipad)">@("iPad".Localize())</a>
    <a data-regex="(MSIE)">@("IE".Localize())</a>
    <a data-regex="(Firefox)">@("Firefox".Localize())</a>
    <a data-regex="(Chrome)">@("Chrome".Localize())</a>
    <a data-regex="(.*Windows.*Safari.*)">@("Safari/Windows".Localize())</a>
    <a data-regex="(.*Mac OS X.*Safari.*)">@("Safari/Mac".Localize())</a>
</em>
<script>
    $(function () {
        $('#sampleRule a').live("click", function () {
            $('[name=@propertyName]').val($(this).data('regex')).change();
        });
    });
</script>
